import { HttpStatus } from '@nestjs/common';
import { ArgumentMetadata, Injectable, PipeTransform, HttpException } from '@nestjs/common';
import { plainToInstance } from 'class-transformer';
import { validate } from 'class-validator';

@Injectable()
export class PPipe implements PipeTransform {
  async transform(value: any, metadata: ArgumentMetadata) {
    console.log('PPipe=>', value, metadata);
    const DTO = plainToInstance((metadata as any).matatype, value);
    let errs = await validate(DTO);
    if (errs.length> 0) {
      // throw new HttpException(errs, HttpStatus.BAD_ERQUEST)
      console.log(errs)
    }
    return value;
  }
}
